export const isNumber = (val: unknown) => typeof val === 'number';
export const isString = (val: unknown) => typeof val === 'string';
export const isObject = (val: unknown) => typeof val === 'object';
export const transformUperCaseRow = (val: string) =>
  val.replace(/[A-Z]/g, (match) => '-' + match.toLowerCase());
export const isFunction = (val: unknown) => typeof val === 'function';

// 获取属性
export function getAttributes(elem: HTMLElement) {
  if (!elem) return {};
  const attrs = {};
  const attrSource = Object.values(elem.attributes);
  attrSource &&
    attrSource.length > 0 &&
    attrSource.forEach((att) => {
      const { name, value } = att;
      const _name = transformUperCaseRow(name);
      attrs[_name] = value;
    });
  return attrs;
}
